package middleware

import (
	"ginWork/pkg"
	"github.com/gin-gonic/gin"
	"net/http"
)

// 定义中间
func MiddleWare() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.GetHeader("token")

		if token == "" {
			c.JSON(http.StatusUnauthorized, gin.H{"code": "-1", "msg": "token不能为空"})

			return
		}

		jwtToken, err := pkg.ParseJwtToken("token2205aaaaaaaaaaaahhh", token)
		if err != nil {

			c.JSON(http.StatusUnauthorized, gin.H{"code": "-2", "msg": "token解析失败"})

			return
		}

		c.JSON(http.StatusOK, gin.H{"code": "200", "data": jwtToken})
	}
}
